package com.cg.big_event.controller;
import com.cg.big_event.entity.Category;
import com.cg.big_event.entity.Result;
import com.cg.big_event.service.CategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/category")
public class    CateGoryController {
    @Resource
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody @Validated(Category.Add.class) Category category){
        categoryService.add(category);
        return Result.success();
    }
    @GetMapping
    public Result<List<Category>> list(){
      List<Category> cs=  categoryService.list();
      return Result.success(cs);
    }
    @GetMapping("/detail")
    public Result<Category> detail(Integer id){
       Category cs= categoryService.detail(id);
       return Result.success(cs);
    }
    @PutMapping
    public Result update(@RequestBody  @Validated(Category.Update.class) Category category)
        {

            categoryService.update (category);
            return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id)
    {
        categoryService.delete(id);
        return Result.success();
    }
}
